package com.github.fancyideas.controller;

import com.github.fancyideas.constance.VIP;
import com.github.fancyideas.repository.CustomerRepository;
import com.github.fancyideas.repository.ShoesHisRepository;
import com.github.fancyideas.repository.ShoesRepository;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "统计数据", tags = {"统计数据"})
@RestController
@RequestMapping("/statistics")
public class DataStatisticsController {

    @Autowired
    private CustomerRepository customerRepository;
    @Autowired
    private ShoesHisRepository shoesHisRepository;
    @Autowired
    private ShoesRepository shoesRepository;

    /**
     * 总客构成
     */
    @GetMapping("/count/customer")
    public Map<String, Object> customerTotal() {
        Map<String, Object> customers = new HashMap<>();
        long customVip = customerRepository.countByVipIs(VIP.YES);
        long customTotal = customerRepository.count();
        customers.put("total", customTotal);
        customers.put("vip", customVip);
        customers.put("unvip", customTotal - customVip);
        return customers;
    }

    /**
     * 存放，一年12个月分组的金额 money
     */
    @GetMapping("/count/shoes/putIn/{month}")
    public List<Map<String, Object>> shoesPutIn(@PathVariable String month) {
        return shoesHisRepository.countShoesEntitiesByYear(month);
    }

    /**
     * 取出&综合收入，一年12个月分组的金额 money
     */
    @GetMapping("/count/shoes/takeOut/{month}")
    public List<Map<String, Object>> shoesTakeOut(@PathVariable String month) {
        return shoesHisRepository.countShoesTakeOutByMonth(month);
    }

    /**
     * 客户信息统计详情
     */
    @GetMapping("/count/customer/detail/{vip}")
    public List<Map<String, Object>> customerInfo(@PathVariable VIP vip) {
        int vipIndex = vip.ordinal();
        return customerRepository.customerInfo(vipIndex);
    }

    /**
     * 存放报表详情
     */
    @GetMapping("/count/shoes/detail/putin/{month}")
    public List<Map<String, Object>> shoesPutinInfo(@PathVariable String month) {
        return shoesHisRepository.queryPutinShoesDetailByMonth(month);
    }

    /**
     * 取出报表详情
     */
    @GetMapping("/count/shoes/detail/takeout/{month}")
    public List<Map<String, Object>> shoesTakeoutInfo(@PathVariable String month) {
        return shoesHisRepository.queryTakeoutShoesDetailByMonth(month);
    }

    /**
     * 综合收入
     */
    @GetMapping("/count/synthetical/{month}")
    public List<Map<String, Object>> syntheticalByMonth(@PathVariable String month) {
        return shoesHisRepository.syntheticalByMonth(month);
    }
}



